/*******************************************************************************
 * Copyright 2013 Mindaugas Idzelis
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package incontrol.bf3.state;

import incontrol.bf3.protocol.events.datatype.BF3Map;
import incontrol.bf3.protocol.events.datatype.GameMode;
import incontrol.bf3.protocol.events.datatype.ServerInfo;
import incontrol.bf3.protocol.events.datatype.TeamScores;

import com.google.common.base.Objects;

public class RoundState {

	public final BF3Map map;
	public final GameMode gameMode;
	public final int curPlayers;
	public final int maxPlayers;
	public final TeamScores teamScores;

	public RoundState() {
		this.map = null;
		this.gameMode = null;
		this.curPlayers = 0;
		this.maxPlayers = 0;
		teamScores = null;
	}

	public RoundState(BF3Map map, GameMode gameMode, int curPlayers,
			int maxPlayers, TeamScores teamScores) {
		this.map = map;
		this.gameMode = gameMode;
		this.curPlayers = curPlayers;
		this.maxPlayers = maxPlayers;
		this.teamScores = teamScores;
	}

	public RoundState update(ServerInfo info) {
		return new RoundState(info.map, info.gamemode, info.currentPlayerCount,
				info.maxPlayerCount, info.teamScores);
	}

	@Override
	public String toString() {
		return Objects.toStringHelper(this).add("map", map)
				.add("gameMode", gameMode).add("curPlayers", curPlayers)
				.add("maxPlayers", maxPlayers).add("teamScores", teamScores)
				.toString();
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(map, gameMode, curPlayers, maxPlayers,
				teamScores);
	}

	@Override
	public boolean equals(Object object) {
		if (object instanceof RoundState) {
			RoundState that = (RoundState) object;
			return Objects.equal(this.map, that.map)
					&& Objects.equal(this.gameMode, that.gameMode)
					&& Objects.equal(this.curPlayers, that.curPlayers)
					&& Objects.equal(this.maxPlayers, that.maxPlayers)
					&& Objects.equal(this.teamScores, that.teamScores);
		}
		return false;
	}

}
